package leetcode;

import java.util.Stack;

public class AreNumbersAscending {
    public static void main(String[] args) {
        AreNumbersAscending areNumbersAscending = new AreNumbersAscending();
        System.out.println(areNumbersAscending.areNumbersAscending("hello world 5 x 5"));
    }

    public boolean areNumbersAscending(String s) {
        String[] strings = s.split(" ");
        Stack<Integer> stack = new Stack<>();
        for (String str : strings) {
            char c = str.charAt(0);
            if ('0' <= c && c <= '9') {
                Integer number = Integer.parseInt(str);
                if (stack.isEmpty()) {
                    stack.push(number);
                } else {
                    Integer top = stack.peek();
                    if (number <= top) {
                        return false;
                    } else {
                        stack.push(number);
                    }
                }
            }
        }
        return true;
    }
}
